package com.shopmall.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class JumpController {

//    @PreAuthorize("hasAnyRole('ROLE_mall','ROLE_sys','ROLE_root')")
    @RequestMapping("/home")
    public String home(HttpSession session, Model model){
        if(session.getAttribute("admin")!=null)
            return "home";
        else {
            model.addAttribute("msg","请先登录！");
            return "login";
        }
    }

    @RequestMapping({"/","/login","/login.html","/index","/index.html"})
    public String login(HttpSession session){
        if(session.getAttribute("admin")==null)
            return "login";
        else
            return "home";
    }

    @RequestMapping({"/exit","/exit.html","logout","logout.html"})
    public String exit(HttpSession session){
        session.removeAttribute("admin");
        return "login";
    }



    //以下是测试功能段
/*
    @RequestMapping("/form")
    public String form(){
        return "form2";
    }

    @RequestMapping("/table")
    public String table(){
        return "table2";
    }

    @RequestMapping("/upload")
    public String upload(){
        return "upload";
    }

 */
}
